package com.thinkgem.jeesite.modules.ship.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.ship.entity.ShipIllegalReport;
import com.thinkgem.jeesite.modules.ship.service.ShipIllegalReportService;

/**
 * 船舶违法举报信息Controller
 * @author lgx
 * @version 2016-04-17
 */
@Controller
@RequestMapping(value = "${adminPath}/ship/shipIllegalReport")
public class ShipIllegalReportController extends BaseController {

	@Autowired
	private ShipIllegalReportService shipIllegalReportService;
	
	@ModelAttribute
	public ShipIllegalReport get(@RequestParam(required=false) String id) {
		ShipIllegalReport entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = shipIllegalReportService.get(id);
		}
		if (entity == null){
			entity = new ShipIllegalReport();
		}
		return entity;
	}
	
	@RequiresPermissions("ship:shipIllegalReport:view")
	@RequestMapping(value = {"shipIllegalReportList", ""})
	public String list(ShipIllegalReport shipIllegalReport, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ShipIllegalReport> page = shipIllegalReportService.findPage(new Page<ShipIllegalReport>(request, response), shipIllegalReport); 
		model.addAttribute("page", page);
		return "modules/ship/shipIllegalReportList";
	}

	@RequiresPermissions("ship:shipIllegalReport:view")
	@RequestMapping(value = "shipIllegalReportForm")
	public String form(ShipIllegalReport shipIllegalReport, Model model) {
		model.addAttribute("shipIllegalReport", shipIllegalReport);
		return "modules/ship/shipIllegalReportForm";
	}

	@RequiresPermissions("ship:shipIllegalReport:edit")
	@RequestMapping(value = "save")
	public String save(ShipIllegalReport shipIllegalReport, Model model, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, shipIllegalReport)){
			return form(shipIllegalReport, model);
		}
		shipIllegalReportService.save(shipIllegalReport);
		renderStringByJbox(response, "提交成功");
		return null;
		
		//addMessage(redirectAttributes, "保存船舶违法举报信息成功");
		//return "redirect:"+Global.getAdminPath()+"/ship/shipIllegalReport/?repage";
	}
	
	@RequiresPermissions("ship:shipIllegalReport:edit")
	@RequestMapping(value = "delete")
	public String delete(ShipIllegalReport shipIllegalReport, RedirectAttributes redirectAttributes) {
		shipIllegalReportService.delete(shipIllegalReport);
		addMessage(redirectAttributes, "删除船舶违法举报信息成功");
		return "redirect:"+Global.getAdminPath()+"/ship/shipIllegalReport/?repage";
	}

}